package com.example.videotest;

import java.io.File;
import java.io.InputStream;
import java.net.URL;

import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.CursorLoader;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity {

	private static final String myTag = "videoTestTag";
	
	/*http://www.youtube.com/watch?feature=player_detailpage&v=OZJalBmtGnQ*/
	/*rtsp://v3.cache8.c.youtube.com/CjYLENy73wIaLQl0Gq0ZlFqSORMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYOiZ6-DisfmsUAw=/0/0/0/video.3gp*/
	private final String youTubeVideoWebPath = "http://www.youtube.com/watch?feature=player_detailpage&v=OZJalBmtGnQ";
	private final String defaultVideoThumbnailPath = "http://img.youtube.com/vi/OZJalBmtGnQ/default.jpg";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {

    	super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        ImageView iv = (ImageView) findViewById(R.id.thumbnail_id);
        
        /*Once the video view is touched by down press gesture, play the video*/
        iv.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {

				Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse(youTubeVideoWebPath));
				startActivity(intent);
			}
		});

        Drawable drawable = LoadImageFromWebOperations(defaultVideoThumbnailPath);
        iv.setImageDrawable(drawable);
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    private Drawable LoadImageFromWebOperations(String url)
    {
         try
         {
             InputStream is = (InputStream) new URL(url).getContent();
             Drawable d = Drawable.createFromStream(is, "src name");
             return d;
         }catch (Exception e) {
             System.out.println("Exc="+e);
             return null;
         }
     }
}
